<template>
  <div>
    <h1>积分的管理</h1>
    <el-button @click="IntegralDeletes()">清空历史积分记录</el-button>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="userId" label="用户id"></el-table-column>
      <el-table-column prop="userName" label="用户积分"></el-table-column>
      <el-table-column prop="userGrade" label="剩下的积分"></el-table-column>
      <el-table-column prop="userVariation" label="积分变动"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="IntegralDelete(scope.row.integralId)">
            删除本次积分变动
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import { IntegralSelect, IntegralDelete, IntegralDeletes } from '@/api/users'
  export default {
    data() {
      return {
        userId: 0,
        tableData: [],
      }
    },
    mounted() {
      this.IntegralSelect()
    },
    methods: {
      IntegralSelect() {
        //this.userId=sessionStorage.getItem("userId"),
        console.log(this.userId)
        IntegralSelect(this.userId).then((res) => {
          this.tableData = res.data
          console.log(res.data)
        })
      },
      IntegralDelete(row) {
        IntegralDelete(row).then((res) => {
          console.log(res.data)
          this.IntegralSelect()
        })
      },
      IntegralDeletes() {
        const row = 1
        console.log(row)
        IntegralDeletes(row).then((res) => {
          console.log(res.data)
          this.IntegralSelect()
        })
      },
    },
  }
</script>
